import java.util.Arrays;
import java.util.StringTokenizer;


class P11057_39643 {

	public static void main(String[] args) {
		
		try {
		
		String line = readLn();
		
		while (line != null) {
			
			int books = Integer.parseInt(line);
			
			int[] booksPrices = new int[books];
			
			StringTokenizer st = new StringTokenizer(readLn());
			
			for (int k = 0; k < books; k++) {
				booksPrices[k] = Integer.parseInt(st.nextToken());
			}
			
			int target = Integer.parseInt(readLn());
			
			Arrays.sort(booksPrices);
			
			int[] result = new int[2];
			result[0] = 0;
			result[1] = 100000000;
			
			int halfTarget = (target / 2) + 1;
			
			for (int k = 0; k < books; k++) {
				if (booksPrices[k] >= halfTarget) continue;
				
				for (int j = k + 1; j < books; j++) {
					
					if (booksPrices[k] + booksPrices[j] == target) {
						if ((result[1] - result[0]) > (booksPrices[j] - booksPrices[k]))  {
							result[1] = booksPrices[j];
							result[0] = booksPrices[k];
						}
					}
				}
				
			}
			
			System.out.println("Peter should buy books whose prices are " + result[0] + " and " + result[1] + ".");
			System.out.println();
			readLn();
			
			line = readLn();
		}
		} catch (ArrayIndexOutOfBoundsException e) {
			while (true) {
				
			}
		}
		
	}
	
	  static String readLn() {
	        String newLine = System.getProperty("line.separator");
	        StringBuffer buffer = new StringBuffer();
	        int car = -1;
	        try {
	            car = System.in.read();
	            while ((car > 0) && (car != newLine.charAt(0))) {
	                buffer.append((char) car);
	                car = System.in.read();
	            }
	            if (car == newLine.charAt(0))
	                System.in.skip(newLine.length() - 1);
	        } catch (java.io.IOException e) {
	            return (null);
	        }
	        if ((car < 0) && (buffer.length() == 0))
	            return (null);
	        return (buffer.toString()).trim();
	    }
	
}
